<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form action="">
        用户名：<input type="text" name="user_name" id="user_name"><br>
        电话：<input type="tel" name="user_tel" id="user_tel" pattern="^1\d{10}$"><br>
        <input type="submit">
    </form><br>
    <script>
        // oninput 在输入框输入时 就会触发
        document.getElementById("user_name").oninput=function(){
            console.log("oninput:"+this.value);
        };
        // onkeyup 当在输入框内 键盘弹起 不包括鼠标复制进输入框
        document.getElementById("user_name").onkeyup = function(){
            console.log("onkeyup:"+this.value);
        };
        //oninvalid 当输入不合法的数据时候 触发
        document.getElementById("user_tel").oninvalid=function(){
            // 设置不合法的自定义提示
            this.setCustomValidity("请输入合法的11的手机号");
        };
    </script>
</body>
</html>